#ifndef CUSTOMWINDOW_H
#define CUSTOMWINDOW_H

#include <QWidget>
#include "TitleBarAbstract.h"
#include "FrameAbstract.h"

class CustomWindow : public QWidget
{
	Q_OBJECT

	int _headerHeight;
	int _frameSize;

	TitleBarAbstract* _titleBar;
	FrameAbstract* _leftFrame;
	FrameAbstract* _rightFrame;
	FrameAbstract* _bottomFrame;
	QWidget* _widget;

	QPoint _mousePos;
	QPoint _lastClick;

	int _state;
	bool _resizable;

	QPixmap* _cacheImage;

	enum ResizeDirection{
		None = 1,
		Left = 2,
		Top = 4,
		Right = 8,
		Bottom = 16,
		Move = 32
	};

	void calculateState(const QPoint& mousePos);
	void resizeWindow(const QPoint& mousePos);
	QSize getMinSizes();
	QSize getMaxSizes();

public:
	explicit CustomWindow(QWidget *parent = 0);
	~CustomWindow();

	void attachWidget(QWidget* widget);
	void attachTitleBar(TitleBarAbstract* titleBar);
	void attachFrame(FrameAbstract* frame);
	void setResizable(bool resizable);
	void setHeaderSize(int height);
	void setFrameSize(int height);

protected:
	void resizeEvent(QResizeEvent *event);
	void paintEvent(QPaintEvent *event);

	void mousePressEvent(QMouseEvent *event);
	void mouseReleaseEvent(QMouseEvent *event);
	void mouseMoveEvent(QMouseEvent *event);
};

#endif // CUSTOMWINDOW_H
